﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.Serialization;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;

namespace CommunitySystemModel
{
    [Serializable]
    [DataContract]
    public class MenuItem : INotifyPropertyChanged
    {
        private int _ID = 0;
        [DataMember]
        public int ID
        {
            get { return _ID; }
            set
            {
                if (_ID != value)
                {
                    _ID = value;
                    this.OnPropertyChanged("ID");
                };
            }
        }

        private string _Title = string.Empty;
        [DataMember]
        [Required(ErrorMessage = "菜单名称必填")]
        public string Title
        {
            get { return _Title; }
            set
            {
                if (_Title != value)
                {
                    _Title = value;
                    //var tmpValidator = new ValidationContext(this, null, null);
                    //tmpValidator.MemberName = "Title";
                    //Validator.ValidateProperty(value, tmpValidator);
                    if (string.IsNullOrEmpty(value))
                        throw new Exception("菜单名称必填");
                    this.OnPropertyChanged("Title");
                };
            }
        }

        private string _Target = string.Empty;
        [DataMember]
        public string Target
        {
            get { return _Target; }
            set
            {
                if (_Target != value)
                {
                    _Target = value;
                    this.OnPropertyChanged("Target");
                };
            }
        }

        private int _Index = 0;
        [DataMember]
        public int Index
        {
            get { return _Index; }
            set
            {
                if (_Index != value)
                {
                    _Index = value;
                    this.OnPropertyChanged("Index");
                };
            }
        }

        private int _PID = 0;
        [DataMember]
        public int PID
        {
            get { return _PID; }
            set
            {
                if (_PID != value)
                {
                    _PID = value;
                    this.OnPropertyChanged("PID");
                };
            }
        }

        private byte[] _icon = null;
        [DataMember]
        public byte[] icon
        {
            get { return _icon; }
            set { _icon = value; }
        }

        private bool _IsDefault = false;
        [DataMember]
        public bool IsDefault
        {
            get { return _IsDefault; }
            set { _IsDefault = value; }
        }
        

        public event PropertyChangedEventHandler PropertyChanged;

        public void OnPropertyChanged(string PropName)
        {
            if (PropertyChanged != null)
            {
                this.PropertyChanged(this, new PropertyChangedEventArgs(PropName));
            }
        }
    }
}
